<?
/**
 * Copyright 2008 Melange.
 *
 * This file is part of Melange CMS
 *
 * @package cms
 *
 */


/**
 * Requirements
 */
require_once("mvc/action/ActionForm.php");
require_once("mvc/action/ActionMessage.php");
require_once("mvc/action/ActionMessages.php");
require_once("cms/gallery/om/GalleryImage.php");



/**
 * BaseImageForm Class
 *
 * @category    Melange CMS
 * @package     cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 */
class BaseImageForm extends ActionForm {


    // ----------------------------------------------------- Instance Variables


    /**
     * galleryImage
     *
     * @var GalleryImage 
     */
    protected $galleryImage;


    /**
     * formFile
     *
     * @var mixed 
     */
    protected $formFile;


    /**
     * path
     *
     * @var mixed 
     */
    protected $path;


    /**
     * resize1
     *
     * @var mixed 
     */
    protected $resize1;


    /**
     * resize2
     *
     * @var mixed 
     */
    protected $resize2;


    // ----------------------------------------------------------- Constructors


    /**
     * Construct new BaseImageForm
     */
    public function __construct() {
        $this->galleryImage = new GalleryImage();
        $this->formFile = null;
        $this->path = null;
        $this->resize1 = null;
        $this->resize2 = null;
    }


    // ------------------------------------------------------------- Properties


    /**
     * Get GalleryImage
     *
     * @return GalleryImage 
     */
    public function getGalleryImage() {
        return $this->galleryImage;
    }


    /**
     * Set GalleryImage
     *
     * @param GalleryImage  galleryImage
     */
    public function setGalleryImage(GalleryImage $galleryImage) {
        $this->galleryImage = $galleryImage;
    }


    /**
     * Get FormFile
     *
     * @return mixed 
     */
    public function getFormFile() {
        return $this->formFile;
    }


    /**
     * Set FormFile
     *
     * @param mixed  formFile
     */
    public function setFormFile($formFile) {
        $this->formFile = $formFile;
    }


    /**
     * Get Path
     *
     * @return mixed 
     */
    public function getPath() {
        return $this->path;
    }


    /**
     * Set Path
     *
     * @param mixed  path
     */
    public function setPath($path) {
        $this->path = $path;
    }


    /**
     * Get Resize1
     *
     * @return mixed 
     */
    public function getResize1() {
        return $this->resize1;
    }


    /**
     * Set Resize1
     *
     * @param mixed  resize1
     */
    public function setResize1($resize1) {
        $this->resize1 = $resize1;
    }


    /**
     * Get Resize2
     *
     * @return mixed 
     */
    public function getResize2() {
        return $this->resize2;
    }


    /**
     * Set Resize2
     *
     * @param mixed  resize2
     */
    public function setResize2($resize2) {
        $this->resize2 = $resize2;
    }


    // --------------------------------------------------------- Public Methods


    /**
     * Validate this form
     *
     * @return array $errors
     */
    public function validate() {

        $errors = new ActionMessages();

        if(is_null($this->getGalleryImage()->getGalleryId()) || strlen($this->getGalleryImage()->getGalleryId()) == 0)
            $errors->add("galleryImage->galleryId",
                new ActionMessage("errors.required", true, new ActionMessage("ID", false)));


        if(!is_null($this->getGalleryImage()->getGalleryId()) && strlen($this->getGalleryImage()->getGalleryId()) > 0 && strlen($this->getGalleryImage()->getGalleryId()) > 255)
            $errors->add("galleryImage->galleryId",
                new ActionMessage("errors.maxlength", true, array(
                    new ActionMessage("ID", false),
                    new ActionMessage("255", false))));


        global $ALLOWABLE_IMAGES;
        if(!is_null($this->getFormFile()) && isset($this->formFile["size"]) && $this->formFile["size"] > 0 && !array_key_exists($this->formFile["type"], $ALLOWABLE_IMAGES))
            $errors->add("formFile",
                new ActionMessage("errors.image", true, new ActionMessage("prompt.image", true)));

        return $errors;
    }

}
?>